package com.lw.sbdemo2.web;

import com.lw.sbdemo2.common.utils.IdUtils;
import com.lw.sbdemo2.common.utils.ValidUtil;
import com.lw.sbdemo2.common.web.anno.Required;
import com.lw.sbdemo2.common.base.BaseController;
import com.lw.sbdemo2.common.vo.PageInfo;
import com.lw.sbdemo2.entity.TkTeacherClassStudent;
import com.lw.sbdemo2.mapper.TkTeacherClassStudentMapper;
import com.lw.sbdemo2.service.TkTeacherClassStudentService;
import com.lw.sbdemo2.common.web.anno.ResultController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>标题: 教师班级学生表服务 - 请求控制层</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2019</p>
 * <p>公司: 山人行工作室</p>
 *
 * @version: 1.0
 * @author: LinWang
 * @date 2019-5-20
 */
@ResultController
@Api(description = "TkTeacherClassStudentController", tags = {"教师班级学生表服务"})
@RequestMapping(value = "/tkTeacherClassStudent")
public class TkTeacherClassStudentController extends BaseController {

    /**
     * 教师班级学生表服务
     */
    @Autowired
    private TkTeacherClassStudentService tkTeacherClassStudentService;
    @Autowired
    private TkTeacherClassStudentMapper tkTeacherClassStudentMapper;

	@ApiOperation(value = "获取教师班级学生表列表")
    @GetMapping("")
    public List<TkTeacherClassStudent> findList(TkTeacherClassStudent tkTeacherClassStudent) {
        return tkTeacherClassStudentService.findList(tkTeacherClassStudent);
    }

    @ApiOperation(value = "获取教师班级学生表列表（分页）", response = PageInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "关键词", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "int"),
    })
    @GetMapping(value = "/page")
    public PageInfo<TkTeacherClassStudent> page(String query, @Required("pageNum") PageInfo pageInfo, TkTeacherClassStudent tkTeacherClassStudent) {
        return tkTeacherClassStudentService.findListPage(query, pageInfo, tkTeacherClassStudent);
    }

    @ApiOperation(value = "获取教师班级学生表详细信息", notes = "根据url的id来获取教师班级学生表详细信息")
    @ApiImplicitParam(name = "id", value = "教师班级学生表ID", required = true, dataType = "String")
    @GetMapping("/{id}")
    public TkTeacherClassStudent get(@PathVariable String id) {
        return tkTeacherClassStudentService.getById(id);
    }

    @ApiOperation(value = "创建教师班级学生表")
    @PostMapping("/insert")
    public void insert(TkTeacherClassStudent tkTeacherClassStudent) {
        tkTeacherClassStudent.setDataId(IdUtils.uuid());
        tkTeacherClassStudent.setValidFlag("1");
        tkTeacherClassStudent.setIsDefault("0");
        tkTeacherClassStudent.setBindTime(new Date());
        tkTeacherClassStudentService.insert(tkTeacherClassStudent);
    }

    @ApiOperation(value = "更新教师班级学生表详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "教师班级学生表ID", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping("/update")
    public void update(TkTeacherClassStudent tkTeacherClassStudent) {
        if(ValidUtil.isNotEmptyAndNull(tkTeacherClassStudent.getIsDefault())){
            tkTeacherClassStudentMapper.updateDefault(tkTeacherClassStudent.getTeacherId());
        }
        tkTeacherClassStudentService.update(tkTeacherClassStudent);
    }

    @ApiOperation(value = "删除教师班级学生表", notes = "删除教师班级学生表")
    @ApiImplicitParam(name = "id", value = "教师班级学生表ID", required = true, paramType = "query", dataType = "String")
    @PostMapping("/delete")
    public void deleteTkTeacherClassStudent(TkTeacherClassStudent tkTeacherClassStudent) {
        tkTeacherClassStudentService.delete(tkTeacherClassStudent);
    }

}
